package com.itheima.reggie.utils;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;

public class Demo {

    public static void main(String[] args) throws Exception {
        //阿里成都服务访问地址
        String endpoint = "https://oss-cn-chengdu.aliyuncs.com";
        //扣钱
        String accessKeyId = "LTAI5tFqhPnXLrqHRvFBSF3m";
        String accessKeySecret = "KbfpJkTsBviAdhYwieVyA7dYIxcUSr";
        // 填写Bucket名称，例如examplebucket。
        String bucketName = "chengdu-reggie-62-huige";
        // 传到阿里云之后，叫什么名字
        String objectName = "123.jpg";

        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\Administrator\\Pictures\\9.jpg");
        try {
            ossClient.putObject(bucketName, objectName, fileInputStream);
        } catch (OSSException oe) {

        } catch (ClientException ce) {
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}